package cn.edu.fudan.bdke.ncov.data.epidemic;

import cn.edu.fudan.bdke.ncov.data.epidemic.model.City;
import cn.edu.fudan.bdke.ncov.data.epidemic.model.Epidemic;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 省的疫情情况
 *
 * @author xym
 * @since 2020/2/13
 */
public abstract class EpidemicSituation {
    protected String date;
    protected Epidemic totalEpidemic; //省的疫情情况
    protected Map<String, Epidemic> cityEpidemicMap;    //下地级行政区的疫情情况

    protected EpidemicSituation() {
        this.date = "";
        this.totalEpidemic = new Epidemic();
        this.cityEpidemicMap = new HashMap<>();
    }

    /**
     * 疫情数据收集
     *
     * @param document 从卫健委网站上获得的字符串数据
     */
    public abstract void collectData(String document);

    /**
     * 获得省下的地级行政区
     *
     * @param filePath 城市列表
     * @return 地级行政区列表
     */
    protected List<String> getCities(String filePath) {
        BufferedReader br = null;
        List<String> cities = new ArrayList<>();
        try {
            br = new BufferedReader(new FileReader(new File(filePath)));
            String curLine = null;
            while ((curLine = br.readLine()) != null) {
                cities.add(curLine);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return cities;
    }

    public Epidemic getTotalEpidemic() {
        return this.totalEpidemic;
    }

    public Map<String, Epidemic> getCityEpidemicMap() {
        return this.cityEpidemicMap;
    }

    public String getDate() {
        return this.date;
    }
}
